package com.cc8w.tag;

import java.io.IOException;
import java.io.StringWriter;

import javax.servlet.jsp.JspContext;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.JspFragment;
import javax.servlet.jsp.tagext.SimpleTagSupport;

public class MyTag2  extends SimpleTagSupport {
	private String time;

	public String getTime() {
		return time;
	}

	public void setTime(String time) {
		this.time = time;
	}
	
	
	@Override
	public void doTag() throws JspException, IOException {
		// TODO Auto-generated method stub
		System.out.println("doTag");
		
		JspContext jspContent = getJspContext();
		JspWriter out =  jspContent.getOut();
		out.print("----显示到页面:"+this.time );
		System.out.println("----------------------");
		
		JspFragment  bodyContent = getJspBody();
		//JspFragment.invoke(Writer):Writer 即为标签体内容输出的字节流,若为null则
		//输出到getJspContext().getOut(),即输出到页面上
		//
		
		//1.直接把值就输出到页面了
		//bodyContent.invoke(null);
		
		//2.这样会处理一下标签体的内容(比如把标签体内容都转为大写)
		StringWriter sw = new StringWriter();
		bodyContent.invoke(sw);
		
		String content = sw.toString().toUpperCase();
		
		//3.使用页面pageContext.out()输出
		out.print("-标签体:"+sw.toString()+" 处理后输出:"+ content );

		
		
	}

	

}
